﻿@using Wheeler.Web.Utility;
@using Wheeler.Common.Extensions;
@using Wheeler.Web.ViewModels;
@using Wheeler.Domain;
@using System.Data;

@{
	String pageTitle = "Backup Database";   
    ViewBag.Title = Html.GetPageTitle(pageTitle);
    ViewData[AppConstants.ViewDataKeys.SELECTED_MENU] = AdminMenu.BackupDatabase;

    //UtilityDAO dao = new UtilityDAO();
    //WheelerEntities _Context = new WheelerEntities();
    //DataSet _ImportedFiles = dao.GetDataSet("SELECT DISTINCT FileName, ImportedOn FROM FixedVehicle GROUP BY FileName", null, false);
    //int _VehicleCount = _Context.Vehicles.Count();
    //int _FinalizedTestResultCount = (from P in _Context.TestResults where P.HasConfirmed && P.HasPublished select P).Count();
    //int _UnfinaledTestResultCount = (from P in _Context.TestResults where !P.HasConfirmed || !P.HasPublished select P).Count();
    //int _TestResultCount = _Context.TestResults.Count();

    //int _FixedVehicleCount = _Context.FixedVehicles.Count();
}

<div class="jb-page-heading">
    <h1>@pageTitle</h1>
    <div>
        Click the button below to generate the latest Database Backup file.
    </div>
</div>

<div class="jb-page-content">
    <a href="javascript:void(0);" class="btn btn-primary" onclick="GenerateBackup();"><i class="icon-briefcase icon-white"></i> Download Backup</a>
</div>

@section JavaScriptPlaceHolder
{
    <script language="javascript" type="text/javascript">
        function GenerateBackup() {
            var url = '/Admin/Account/GenerateBackup';
            ShowLoadingAnimation(false);
            Ajax(url, null, function (fileName) {                
                if (fileName.length > 0) {
                    //$('#aDownload').removeClass('hidden').attr('href', fileName);
                    //$('#aEdit').addClass('disabled').attr('href', 'javascript:void(0);');
                    window.location = '/Admin/Account/DownloadBackup?File=' + fileName;
                    HideLoadingAnimation();
                }
            });
        }
    </script>
}